/*******************************************************************************
*   Copyright (C) Harbin Institute of Technology, Shenzhen.
*				  All Rights Reserved.
*   Department: Decoration
********************************************************************************
* File Name   : encoder.h
* Author      : Dayuan
* Version     : v0.01
* Date        : 2019/9/5
* Description : Decoration Rototics Manipulator task.
*******************************************************************************/
/*-History----------------------------------------------------------------------
* Version   Date      Name        Changes and comments
* v0.01     2019/9/5  Dayuan    initial version
*=============================================================================*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _ENCODER_H_
#define _ENCODER_H_

#ifdef __cplusplus
 extern "C" {
#endif
     
/**** Includes ****/
#include <stdint.h>
     
/**** Definition of constants ****/
 
/**** Definition of types ****/ 
typedef enum
{
	ENC_INC_CW,		/* clockwise rotation */
	ENC_INC_CCW,	/* counterclockwise rotation */
}ENC_INC_DIR_TYPE;

typedef struct
{
	uint8_t valid; 		/*	zero calibration finished?	*/
	uint32_t cpr;
	uint32_t gear_ratio;
	uint64_t total_cnt;
	uint32_t cur_cnt;
	uint32_t last_cnt;
	int32_t turn;
	uint64_t scaled;
	ENC_INC_DIR_TYPE dir;
	uint32_t z_cnt;		/* cnt valu when z exit point*/
	float angle;
}ENC_INC_INFO;

/**** Definition of macros ****/
//#define ENC_Z_EXIT

/**** Declaration of constants ****/


/**** Declaration of variables ****/
extern ENC_INC_INFO enc_inc;

/**** Declaration of functions ****/
extern void enc_inc_z_exit_handle(void);
extern void encoder_polling(void);
extern void enc_reset_create(void);
extern void enc_inc_calibration(void);

static uint32_t enc_get_cnt(void);
static ENC_INC_DIR_TYPE enc_get_dir(void);

#ifdef __cplusplus
}
#endif

#endif
